package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.pojo.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.CategoryManagementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description FoodManagementController
 * @Author luohai
 * @Date 2024-09-30
 */
@RestController
@RequestMapping("/admin/category")
@Slf4j
@Api(tags = "分类管理")
public class CategoryManagementController {
    @Autowired
    private CategoryManagementService categoryManagementService;

    /**
     * 新增分类
     *
     * @param categoryDTO
     * @return
     */
    @PostMapping
    @ApiOperation("新增分类")
    public Result addCategory(@RequestBody CategoryDTO categoryDTO) {
        categoryManagementService.addCategory(categoryDTO);
        return Result.success();
    }

    /**
     * 分类分页查询
     *
     * @param categoryPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("分类分页查询")
    public Result classificationPaginationQuery(CategoryPageQueryDTO categoryPageQueryDTO) {
        PageResult pageResult = categoryManagementService.classificationPaginationQuery(categoryPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 根据ID删除分类
     *
     * @param id
     * @return
     */
    @DeleteMapping
    @ApiOperation("根据ID删除分类")
    public Result deleteCategoryById(Integer id) {
        categoryManagementService.deleteCategoryById(id);
        return Result.success();
    }

    /**
     * 根据ID修改分类
     *
     * @param category
     * @return
     */
    @PutMapping
    @ApiOperation("根据ID修改分类")
    public Result changeClassificationById(@RequestBody Category category) {
        categoryManagementService.changeClassificationById(category);
        return Result.success();
    }

    /**
     * 启用禁用分类
     * @param status
     * @return
     */
    @PostMapping("/status/{status}")
    @ApiOperation("启用禁用分类")
    public Result enableAndDisableClassification(@PathVariable Integer status,Integer id){
        categoryManagementService.enableAndDisableClassification(status,id);
        return Result.success();
    }

    /**
     * 根据类型查询分类
     * @param type
     * @return
     */
    @GetMapping("/list")
    public Result list(Integer type){
        List<Category> category=categoryManagementService.list(type);
        return Result.success(category);
    }
}
